package com.px.project.module.ht.service.impl;

import java.util.List;

import com.px.common.dto.BaseQueryDto;
import com.px.common.service.ISysProjectCompanyService;
import com.px.project.module.ht.entity.ConstructionProtect;
import com.px.project.module.ht.mapper.ConstructionProtectMapper;
import com.px.project.module.ht.service.ConstructionProtectService;
import com.px.project.module.ht.vo.ConstructionProtectVo;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.hutool.core.bean.BeanUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 施工防护管理 服务实现类
 *
 * @author 品讯科技
 * @since 2023-10-07
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ConstructionProtectServiceImpl extends ServiceImpl<ConstructionProtectMapper, ConstructionProtect>
    implements ConstructionProtectService {
    private final ISysProjectCompanyService sysProjectCompanyService;

    @Override
    public Page<ConstructionProtectVo> page(BaseQueryDto<ConstructionProtect> pageVo, ConstructionProtect constructionProtect) {
        LambdaQueryWrapper<ConstructionProtect> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.setEntity(constructionProtect);
        Page<ConstructionProtect> page = super.page(pageVo.toPage(), queryWrapper);
        List<ConstructionProtect> constructionProtects = page.getRecords();
        List<ConstructionProtectVo> constructionProtectList = BeanUtil.copyToList(constructionProtects, ConstructionProtectVo.class);
        constructionProtectList.forEach(constructionProtectVo -> constructionProtectVo
            .setCompanyName(this.sysProjectCompanyService.getById(constructionProtectVo.getCompanyId()).getCompanyName()));
        Page<ConstructionProtectVo> pages = BeanUtil.copyProperties(page, Page.class);
        return pages.setRecords(constructionProtectList);
    }
}